home *** CD-ROM | disk | FTP | other *** search
- program super_tetris;
- uses crt;
- const nbpiece=27;
- large=20;
- haut=23;
- gauche='4';
- droite='6';
- tombe='2';
- rotation=' ';
- temporisation=8000;
- xposition_depart=4;
- yposition_depart=4;
- block='▓▓';
- type p = RECORD
- x: array[1..4] of integer;
- y: array[1..4] of integer;
- c: byte;
- END;
- ens = array [0..nbpiece] of p;
- tab = array [1..large,1..haut] of byte;
-
- var e : ens;
- i,j,k,ti,tj: integer;
- a: char;
- t: tab;
- xp,yp,xa,ya,nb: byte;
-
- PROCEDURE INIT;
- BEGIN
- for i:=0 to nbpiece do
- for j:=1 to 4 do
- BEGIN
- e[i].x[j]:=0;
- e[i].y[j]:=0;
- e[i].c:=3;
- END;
- with e[0] do BEGIN x[1]:=-1;x[3]:=1;x[4]:=2;END;
- with e[1] do BEGIN x[1]:=-1;x[3]:=1;x[4]:=0;y[4]:=1;END;
- with e[2] do BEGIN x[1]:=-1;x[3]:=1;x[4]:=-1;y[4]:=1;END;
- with e[3] do BEGIN x[2]:=1;x[4]:=1;y[3]:=1;y[4]:=1;END;
- with e[4] do BEGIN x[1]:=-1;x[3]:=1;x[4]:=1;y[4]:=1;END;
- with e[5] do BEGIN x[2]:=1;x[4]:=1;y[3]:=-1;y[4]:=1;END;
- with e[6] do BEGIN x[2]:=1;x[4]:=1;y[3]:=1;y[4]:=-1;END;
- with e[7] do BEGIN y[1]:=-2;y[2]:=-1;y[4]:=1;END;
- with e[8] do BEGIN x[4]:=1;y[1]:=-1;y[3]:=1;END;
- with e[9] do BEGIN x[4]:=1;y[1]:=-1;y[3]:=1;y[4]:=1;END;
- with e[10] do BEGIN x[2]:=1;x[4]:=1;y[3]:=1;y[4]:=1;END;
- with e[11] do BEGIN x[4]:=1;y[1]:=-1;y[3]:=1;y[4]:=-1;END;
- with e[12] do BEGIN x[2]:=1;x[3]:=-1;y[3]:=1;y[4]:=1;END;
- with e[13] do BEGIN x[2]:=-1;x[4]:=1;y[3]:=1;y[4]:=1;END;
- with e[14] do BEGIN x[1]:=-1;x[3]:=1;x[4]:=2;END;
- with e[15] do BEGIN x[1]:=-1;x[3]:=1;y[4]:=-1;END;
- with e[16] do BEGIN x[1]:=-1;x[3]:=1;x[4]:=1;y[4]:=-1;END;
- with e[17] do BEGIN x[2]:=1;x[4]:=1;y[3]:=1;y[4]:=1;END;
- with e[18] do BEGIN x[1]:=-1;x[3]:=1;x[4]:=-1;y[4]:=-1;END;
- with e[19] do BEGIN x[2]:=1;x[4]:=1;y[3]:=-1;y[4]:=1;END;
- with e[20] do BEGIN x[2]:=1;x[4]:=1;y[3]:=1;y[4]:=-1;END;
- with e[21] do BEGIN y[1]:=-2;y[2]:=-1;y[4]:=1;END;
- with e[22] do BEGIN x[1]:=-1;y[4]:=1;y[3]:=-1;END;
- with e[23] do BEGIN x[1]:=-1;y[1]:=-1;y[2]:=-1;y[4]:=1;END;
- with e[24] do BEGIN x[2]:=1;x[4]:=1;y[3]:=1;y[4]:=1;END;
- with e[25] do BEGIN x[4]:=-1;y[1]:=-1;y[3]:=1;y[4]:=1;END;
- with e[26] do BEGIN x[2]:=1;x[3]:=-1;y[3]:=1;y[4]:=1;END;
- with e[27] do BEGIN x[2]:=-1;x[4]:=1;y[3]:=1;y[4]:=1;END;
-
- for i:=1 to large do
- for j:=1 to haut do t[i,j]:=0;
- for i:=1 to large do t[i,haut]:=255;
- for i:=1 to haut do BEGIN
- t[1,i]:=255;
- t[large,i]:=255;
- END;
- END;
-
- FUNCTION collision(nb,xp,yp: byte):boolean;
- var test: boolean;
- BEGIN
- test:=false;
- for i:=1 to 4 do
- if t[xp+e[nb].x[i],yp+e[nb].y[i]]<>0 then test:=true;
- collision:=test;
- END;
-
- PROCEDURE AFFICHE_PIECE;
- BEGIN
- for i:=1 to 4 do BEGIN
- gotoxy((xp+e[nb].x[i])*2,yp+e[nb].y[i]);
- write(block);
- END;
- END;
- PROCEDURE EFFACE_PIECE;
- BEGIN
- for i:=1 to 4 do BEGIN
- gotoxy((xp+e[nb].x[i])*2,yp+e[nb].y[i]);
- write(' ');
- END;
- END;
-
- PROCEDURE AFFICHE_TABLEAU;
- BEGIN
- for i:=1 to large do
- for j:=1 to haut do
- BEGIN
- gotoxy(i*2,j);
- if t[i,j]=0 then write(' ')
- else write(block);
- END;
- END;
- PROCEDURE TESTE_LIGNE;
- var test: boolean;
- BEGIN
- j:=haut-1;
- repeat
- test:=true;
- for i:=2 to large-1 do
- if t[i,j]=0 then test:=false;
- dec(j);
- until (test) or (j=1);
- inc(j);
- if test then
- BEGIN
- for tj:=j downto 2 do
- for i:=1 to large do
- t[i,tj]:=t[i,tj-1];
- END;
- if test then BEGIN
- AFFICHE_TABLEAU;
- END;
- END;
-
-
- PROCEDURE GERE_TOUCHE(a:char);
- var nbtampon:byte;
- BEGIN
- case a of
- gauche: if not(collision(nb,xp-1,yp)) then
- BEGIN
- efface_piece;
- xp:=xp-1;
- END;
- droite: if not(collision(nb,xp+1,yp)) then
- BEGIN
- efface_piece;
- xp:=xp+1;
- END;
- tombe: k:=temporisation*4;
- rotation: BEGIN
- efface_piece;
- nbtampon:=nb;
- if nb+7>nbpiece then nbtampon:=nb-21
- else nbtampon:=nb+7;
- if not(collision(nbtampon,xp,yp)) then nb:=nbtampon;
- END;
- END;
- affiche_piece;
- END;
-
- function DESCENDRE:boolean;
- BEGIN
- if not(collision(nb,xp,yp+1)) then
- BEGIN
- EFFACE_PIECE;
- yp:=yp+1;
- DESCENDRE:=TRUE;
- END
- else
- DESCENDRE:=FALSE;
- END;
-
- PROCEDURE INSERE_PIECE_DANS_TAB;
- BEGIN
- for i:=1 to 4 do t[xp+e[nb].x[i],yp+e[nb].y[i]]:=255;
- END;
-
-
- PROCEDURE NOUVELLE_PIECE;
- BEGIN
- xp:=xposition_depart;
- yp:=yposition_depart;
- nb:=random(28);
- END;
-
- BEGIN
- randomize;
- a:='g';
- init;
- clrscr;
- AFFICHE_TABLEAU;
- NOUVELLE_PIECE;
- AFFICHE_PIECE;
- k:=0;
- repeat
- repeat
- inc(k);
- until (keypressed) or (k>temporisation);
- if keypressed then
- BEGIN
- a:=readkey;
- gere_touche(a);
- END;
- if k>temporisation then
- BEGIN
- k:=k-temporisation;
- if not(DESCENDRE) then
- BEGIN
- INSERE_PIECE_DANS_TAB;
- for ti:=1 to 4 do TESTE_LIGNE;
- NOUVELLE_PIECE;
- k:=0;
- END;
- END;
- AFFICHE_PIECE;
- until a='q';
- END.
-
-